<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <title>StringField Test Suite</title>
    <script type="text/javascript" src="../js/inputex-loader.js"></script>
</head>
<body class="yui-skin-sam">
<h1>
    <script>document.write(document.title)</script>
</h1>

<div id="test"></div>

<script type="text/javascript">
    inputEx.YUI({base:'../lib/yui3/',inputExBase:'../'}).use('node', 'console', 'yuitest', 'stringfield', function(Y) {
        Y.namespace('inputEx.tests')
        Y.inputEx.tests.StringFieldTests = new Y.Test.Case({
            name: 'String Field Tests',
            setUp:function() {
                this.data = {}
                Y.get('#test').set('innerHTML', '')
            },
            tearDown:function() {
                delete this.data;
            },

            testLoader:function() {
                Y.Assert.isTrue(typeof(Y.inputEx) !== 'undefined')
                Y.Assert.isTrue(typeof(Y.inputEx.StringField) !== 'undefined')
            },

            testConstructor:function() {
                var test01 = new Y.inputEx.StringField()
                Y.Assert.isNotUndefined(test01)
                Y.Assert.isInstanceOf(Y.inputEx.StringField, test01, 'The field is not a Y.inputEx.StringField')
                //Y.Assert.isObject(test01.get('boundingBox'))
                //Y.get('#test').contains(test01.get('boundingBox'))
            },

            testRendering:function() {
                var container = Y.Node.create('<div id="testRendering"></div>')
                Y.get('#test').appendChild(container)

                var test = new Y.inputEx.StringField()
                Y.Assert.isNotUndefined(test)
                Y.Assert.isNull(container.query('input'))
                test.render(container)
                Y.Assert.isNotUndefined(container.query('input'))
            },

            XtestStringFieldDOMStructure:function() {
                var container = Y.Node.create('<div id="testStringFieldDOMStructure"></div>')
                Y.get('#test').appendChild(container)

                var field = new Y.inputEx.StringField()
                field.render(container);
            },

            testTypeInvite:function() {
                var container = Y.Node.create('<div id="testTypeInvite"></div>')
                Y.get('#test').appendChild(container)

                var field = new Y.inputEx.StringField({typeInvite:'typeInvite'});
                field.render(container);

                //type invite shall be shown on render as value is null
                Y.Assert.isTrue(field.get('boundingBox').hasClass('inputEx-typeInvite'), 'boundingBox has no inputEx-typeInvite class')
                Y.Assert.areEqual('typeInvite', field._getInputEl().get('value'))

                //update value

                field.set('value', 'value is not empty');
                Y.log('to sync UI', 'warn','Test')
                field.syncUI();
                Y.Assert.areEqual(field.get('value'), field._getInputEl().get('value'))
                Y.Assert.isFalse(field.get('boundingBox').hasClass('inputEx-typeInvite'), 'inputEx-typeInvite shall have been removed')

            }


        })

        Y.inputEx.tests.DevTests = new Y.Test.Case({
            name: 'Development Tests',
            setUp:function() { this.data = {} },
            tearDown:function() { delete this.data; },



            XLastFunction:function() {}
        })


        //TODO: https://sourceforge.net/tracker2/?func=detail&atid=836476&aid=2431381&group_id=165715
        var console = new Y.Console()
        console.get('contentBox').setStyle('width', (Y.get('body').get('docWidth') * 3 / 4) + 'px')
        console.render()
        console.get('contentBox').query('div .yui-console-bd').setStyle('height', (Y.get('body').get('docHeight') * 4 / 5) + 'px')
        console.on('entry', function(e) {if (e.message.source !== 'TestRunner') { e.preventDefault()} })

        Y.Test.Runner.add(Y.inputEx.tests.DevTests);
        if (!Y.inputEx.any(Y.inputEx.tests.DevTests, function(v, k) { return /^test/.test(k) })) {
            // if there are any development tests, normal test won't run
            Y.Test.Runner.add(Y.inputEx.tests.StringFieldTests);
        }
        Y.Test.Runner.run();

    })
</script>
</body>

</html>
